<?php

defined('THINK_PATH') or exit();
//提供jquery load加载
class LoadAction extends AdminCommAction{
    /**
     * 分配权限
     */
    public function rule_group(){
        if(IS_POST){
            $data=I('post.');
            //$data['rules']=implode(',', $data['rule_ids']);
            $result=D('auth_group')->where(array('id'=>$data['id'])) ->save($data);
            if ($result) {
                $this->success('操作成功',U('ADMINADSS/Load/userGroups'));
            }else{
                $this->error('操作失败');
            }
        }else{
            $id=I('get.id');
            // 获取用户组数据
            $group_data=M('auth_group')->where(array('id'=>$id))->find();
            $group_data['roles']=explode(',', $group_data['rules']);
            // 获取规则数据

            $map['fid'] = array('neq',0);
            $rule_data=D('auth_rule')->where($map)->Field('id,fid as pId,title as name') ->select();

            $this->assign('group_data',$group_data);// 赋值分页输出
            $this->assign('list',$rule_data);// 赋值分页输出
            $this->assign('ztreelist',json_encode($rule_data));// 赋值分页输出
            $this->display();
        }
    }
	
	//显示用户组
	public function userGroups(){
        $mod = D("auth_group");
        $list = $mod->select();
        $endjs = '
            function edit(n,i){
                $("#titlsn").val(n);
                $("#sids").val(i);
            }';
        $this->assign('list',$list);// 赋值分页输出
        $this->assign('endjs',$endjs);// 赋值分页输出
        $this->display();
	}

    //删除用户组
    public function delesy($id){
        if(!$id){
            $this->error("请先选择用户组");
        }
        $mod = M("auth_group");
        $dele=$mod->where(array($mod->getPk() => $id))->delete();
        if($dele){
            $this->Record('删除用户组成功');//后台操作
            $this->success('删除成功');
        }else{
            $this->Record('删除用户组失败');//后台操作
            $this->error("删除失败");
        }
    }

}
?>